package com.itlong.cloud.controller.parking;

import com.itlong.cloud.POJO.DTO.operate.ParkingRecordPageDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.OperateFixedCarFeeRecordVO;
import com.itlong.cloud.POJO.VO.operate.OperateTemporaryCarFeeRecordVO;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.paymenthub.IOperateParkingFeeRecordServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-智慧停车-停车缴费记录控制器.
 * </desc>
 *
 * @createDate 2018/11/5
 */
@RestController
@RequestMapping("/parking")
public class OperateParkingFeeRecordController {

    private  static final Logger LOG = LoggerFactory.getLogger(OperateParkingFeeRecordController.class);

    @Autowired
    IOperateParkingFeeRecordServiceClient operateParkingFeeRecordServiceClient;

    /**
     * <desc>
     *      固定车缴费记录分页查询
     * <desc/>
     *
     * @param feeRecordDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "/fixedCarFeeRecord")
    public Object fixedCarFeeRecordPage(ParkingRecordPageDTO feeRecordDTO){
        try{
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            feeRecordDTO= HttpProtocolUtil.parseRequestParamToDTO(ParkingRecordPageDTO.class,request);
            if(feeRecordDTO == null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<OperateFixedCarFeeRecordVO> page = operateParkingFeeRecordServiceClient.getFixedCarFeeRecordPage(feeRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        }catch (Exception e){
            throw new DataAccessException("【运营_智慧停车】获取固定车缴费分页查询列表失败",e);
        }
    }

    /**
     * <desc>
     *      临时车缴费记录分页查询
     * <desc/>
     *
     * @param feeRecordDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "/temporaryCarFeeRecord")
    public Object temporaryCarFeeRecordPage(ParkingRecordPageDTO feeRecordDTO){

        try{
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            feeRecordDTO= HttpProtocolUtil.parseRequestParamToDTO(ParkingRecordPageDTO.class,request);
            if(feeRecordDTO == null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<OperateTemporaryCarFeeRecordVO> page = operateParkingFeeRecordServiceClient.getTemporaryCarFeeRecordPage(feeRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        }catch (Exception e){
            throw new DataAccessException("【运营_智慧停车】获取临时车缴费分页查询列表失败",e);
        }
    }
}